/*
 * @Author: yuanxiaohu
 * @Date: 2025-06-21 20:07:42
 * @LastEditors: yuanxiaohu
 * @LastEditTime: 2025-06-22 00:27:24
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \wine-trend-hui-18\miniprogram\pages\invited\index.js
 */
// formDisplay.js
const app = getApp();
Page({
    data: {
        isLoading: false,
        inviteRole: 1, // 1-会员 2-代理商
        formOption: {
            applyTime: true,
            applyNickName: true,
            applyName: true,
            applyPhone: true,
            applyWx: true,
            applyMsg: true
        },
        agentFormOption: {
            userName: true,
            contact: true,
            phone: true,
            email: true,
            address: true,
            business: true,
            saleChannel: true,
            businessLicense: true,
            foodBusinessLicense: true,
            idCard: true
        },
        businessLicenseFiles: [],
        foodLicenseFiles: [],
        idCardFiles: [],
        navBarHeight: app.globalData.navBarHeight,
        userInfo: null
    },

    onLoad(options) {
        this.setData({
            inviteRole: parseFloat(options.type),
            userInfo: wx.getStorageSync('userInfo')
        });

        this.getFormSettings();
    },
    // 营业执照上传回调
    onBusinessLicenseUpload(event) {
        this.setData({
            businessLicenseFiles: event.detail.fileList
        });
    },
    // 获取表单设置
    getFormSettings() {
        const { inviteRole } = this.data
        this.setData({
            loading: true
        });
        wx.cloud.callFunction({
            name: 'formSettings',
            data: {
                type: 'getFormSettings',
                data: {
                    inviteRole,
                    _openid: this.data.userInfo._openid
                }
            }
        }).then(res => {
            const result = res.result;
            if (result.success) {
                if (inviteRole === 1) {
                    this.setData({
                        formOption: result.formOption
                    });
                } else if (inviteRole === 2) {
                    this.setData({
                        agentFormOption: result.formOption
                    });
                }
                this.setData({
                    loading: false
                });
            }
        }).catch(err => {
            console.error('获取表单设置失败', err);
            this.setData({
                loading: false
            });
        });
    }
});